/*
 * @Author: Setsuna
 * @Email: 601890383@qq.com
 * @FilePath: \src\pages\QuotaManage\Report\InventoryMonitoringReport\components\InnerTable.tsx
 * @Date: 2021-12-14 16:06:58
 * @LastEditTime: 2022-08-12 16:56:28
 */
import { UdTable } from '@/lib'
import { http } from '@/lib'
import React from 'react'
import { useState, useEffect } from 'react'
import quotaApis from '@/apis/AboutQuota'
interface Props {
  record: any
}

export const InnerTable = (props: Props) => {
  const [columns, setColumns] = useState([])
  const [tableData, setTable] = useState([])
  const [loading, setLoading] = useState(false)
  useEffect(() => {
    getTableData()
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

  const getTableData = () => {
    setLoading(true)
    http
      .post(quotaApis.queryDealerInventoryControlMoves, props.record)
      .then(res => {
        const { data } = res
        let col = []
        let dataSource = [{}]
        for (let item of data) {
          let colItem: any = { title: item.month, dataIndex: item.month }
          dataSource[0][item.month] = item.nowMove || '-'
          col.push(colItem)
        }
        console.log(dataSource)
        setColumns(col)
        setTable(dataSource)
      })
      .finally(() => {
        setLoading(false)
      })
  }

  return <UdTable rowKey={(record, index) => index + ""} columns={columns} dataSource={tableData} loading={loading} pagination={false} />
}
